<%--
  Created by IntelliJ IDEA.
  User: DYS
  Date: 2022/1/15
  Time: 1:26
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>file upload</title>
</head>
<body>
<form action="/dcxtmv/file/fileupload.do" method="post" enctype="multipart/form-data">
<%--    <label>文件上传</label>--%>
<%--    <input type="file" name="file">--%>
<%--    <input type="submit" value="提交">--%>
    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-2">
            <span class="c-red">*</span> 头像：
        </label>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <img id="pic3" src="" width="106" alt="">
        <input type='file' style="width: 200px;" name='picPaths3'id='picPaths3'
               onchange="showPic(this, 3);" />
    </div>
</form>
</body>

<script>
    //图片回显+图片格式+文件类型
    function showPic(obj, id) {
        var newPreview = document.getElementById('pic'+id);
        if (obj) {
            //ie浏览器兼容
            if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
                obj.select();
                newPreview.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);";

                var path = document.selection.createRange().text;
                var flag = judgeImgSuffix(path);
                if(flag){
                    newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = document.selection.createRange().text;
                }else{
                    alert("要求图片格式为png,jpg,jpeg,bmp");
                }

                return;
            }

            newPreview.src = obj.value;
            return;
        }
    }

    function judgeImgSuffix(path){
        var index = path.lastIndexOf('.');
        var suffix = "";
        if(index > 0){
            suffix = path.substring(index+1);
        }
        if("png"==suffix || "jpg"==suffix || "jpeg"==suffix || "bmp"==suffix || "PNG"==suffix || "JPG"==suffix || "JPEG"==suffix || "BMP"==suffix){
            return true;
        }else{
            return false;
        }
    }
    //异步上传图片
    $.ajaxFileUpload({
        type:"post",
        url:contextPath+"/dcxtmv/file/fileupload.do",
        secureuri:false,
        data:{userName:userName, account:account, sex:sex,
            password:password,
            telephone:telephone, unitId:unitId, groupId:groupId
        },
        dataType: 'text',
        fileElementId:"picPaths3",
        cache:false,
        async:false,
        success:function(data,textStatus,jqXHR){
            //data是返回的数据
            //textStatus 可能为"success","notmodified"等
            //jqXHR 是通过jQuery封装的XMLHttpRequest对象
            if(data==1){
                var msg="信息新增成功！";
                var option = {
                    title: "提示",
                    btn:parseInt("0011",2),
                    onOk:function(){

                        var index = parent.layer.getFrameIndex(
                            window.name);
                        parent.location.replace(parent.location
                            .href);
                        parent.layer.close(index);

                    }
                }
                window.wxc.xcConfirm(msg, "success", option
                );
            }else{
                window.wxc.xcConfirm("新增信息时出现异常！ ","info");
            }
        },
        error:function(XMLHttpRequest,textStatus,errorThrownn){
        window.wxc.xcConfirm("新增信息时出现异常，异常信息："+textStatus,"error");
        return false;
    }
    });

</script>
</html>
